<?php
class estateMod extends base{
	public function __construct(){
		parent::__construct();
		$this->auto_status();//自动审核
	}
	public function index(){
		$type = intval($_GET['type']) ? intval($_GET['type']) : 1;
		//分页
		$page=new Page();
		$page->pageSuffix=cpConfig::get('URL_HTML_SUFFIX');
		$listRows=40;//每页显示的信息条数
		$cur_page=$page->getCurPage();
		$limit_start=($cur_page-1)*$listRows;
		$limit=$limit_start.','.$listRows;

		$db = model();
		//属性
		$apartment = $this->getProperty('apartment');//户型
		$certificate = $this->getProperty('certificate');//证书
		$decoration = $this->getProperty('decoration');//装修
		$structure = $this->getProperty('structure');// 结构
		$address = $this->getProperty('address');// 地址


		//房源
		$table = "estate";
		$where = " type=".$type;
		$where .= $this->sql();//取得查询条件
		$order = 'top desc,apartment asc,shi asc,ting asc,wei asc,chu asc,yang asc,netid asc,dateline desc';
		if ($_GET['export']) {//导出
			$data = $db->table($table)->field($field)->where($where)->order($order)->select();
			if (!$data) $this->error('没有找到您要导出的数据');
			foreach ($data as $key => $val){
				$data[$key]['aname'] = $apartment[$val['apartment']]['name'];
				$data[$key]['huxing'] = $this->_huxing($val);
				$data[$key]['dname'] = $decoration[$val['decoration']]['name'];
				$data[$key]['cname'] = $certificate[$val['certificate']]['name'];
				$data[$key]['sname'] = $structure[$val['structure']]['name'];
			}
			$this->export($data,$type);
			exit;
		}
		/*
		if($_GET['compare']){
			$order = "address ASC ,apartment ASC,decoration ASC, certificate ASC, decoration ASC,";
		}
*/

		//信息总数
		$count = $db->table($table)->where($where)->count();
		//当页信息列表
		$result = $db->table($table)->field($field)->where($where)->limit($limit)->order($order)->select();
		//echo $db->sql;
		if ($result) {
			foreach ($result as $key => $val){				
				$result[$key]['aname'] = $apartment[$val['apartment']]['name'];
				$result[$key]['huxing'] = $this->_huxing($val);
				$result[$key]['dname'] = $decoration[$val['decoration']]['name'];
				$result[$key]['cname'] = $certificate[$val['certificate']]['name'];
				$result[$key]['sname'] = $structure[$val['structure']]['name'];				
			}
		}

		//获取行数
		$pagestring = $page->show($url,$count,$listRows,10,4);

		$this->assign('estate_count',$estate_count['num']);
		$this->assign('list',$result);
		$this->assign('type',$type);
		$this->assign('pagestring',$pagestring);

		$this->assign('apartment',$apartment);
		$this->assign('certificate',$certificate);
		$this->assign('decoration',$decoration);
		$this->assign('structure',$structure);
		$this->assign('address',$address);

		$this->display();
	}
	//批量删除
	public function batdel(){
		if ($_POST) {
		
			$year = intval($_POST['year']);
			$month = intval($_POST['month']);
			$end_year = $year;
			$end_month = $month+1;
			if($end_month>12){
				$end_month=1;
				$end_year=$year+1;
			}
			$time = $year."-".$month."-1";
			$end_time = $end_year."-".$end_month."-1";
			//echo $time.'&&'.$end_time."<br>";
			$time = strtotime($time);
			$end_time = strtotime($end_time);	
			//echo $time.'&&'.$end_time."<br>";
			//echo date('Y-m-d',$time).'&&'.date('Y-m-d',$end_time);
			$db = model('estate');
			$db->where("dateline >$time and dateline<$end_time")->delete();
			
			$count = model('count');
			$where['year'] = intval($_POST['year']);
			$where['month'] = intval($_POST['month']);
			$count->where($where)->delete();
			
			$this->success('记录删除成功');
			
			exit;
		}
		$this->display();
	}
	//搜索语句处理
	public function sql(){
		$where = '';
		//导出时使用
		if ($_GET['date']) {
			$day = intval($_GET['date']);
			$time = time();
			$time = strtotime(date('Y-m-d',$time));
			if($this->_G['member']['usergroup']==1){
				$time = $time - ( 3600*24*($day-1) );
				$where .= " and dateline>".$time;
			}else{//非管理员下载今天之前的数据
				$today = $time - (3600*24);
				$time = $time - ( 3600*24*($day-1) ) - (3600*24);
				$where .= " and dateline>".$time." and dateline<".$today;
			}
		}
		//列表页使用
		/*if (is_numeric($_GET['apartment'])) {
		$where .= " and apartment=".intval($_GET['apartment']);
		}*/
		if ($_GET['apartment']) {
			$where .= " and apartment={$_GET['apartment']}";
		}
		
		intval($_GET['shi']) && $where .= " and shi=".intval($_GET['shi']);
		intval($_GET['ting']) && $where .= " and ting=".intval($_GET['ting']);
		intval($_GET['wei']) && $where .= " and wei=".intval($_GET['wei']);
		intval($_GET['chu']) && $where .= " and chu=".intval($_GET['chu']);
		intval($_GET['yang']) && $where .= " and yang=".intval($_GET['yang']);
		//面积
		switch ($_GET['area']){
			case 1:
				$where .= " and area between 0 and 30";
				break;
			case 2:
				$where .= " and area between 30 and 60";
				break;
			case 3:
				$where .= " and area between 60 and 90";
				break;
			case 4:
				$where .= " and area between 90 and 120";
				break;
			case 5:
				$where .= " and area between 120 and 150";
				break;
			case 6:
				$where .= " and area > 150";
				break;
			default:
		}
		//时间
		if ($_GET['start']) {
			$where .= " and dateline >".strtotime($_GET['start']);
		}
		if ($_GET['end']) {
			$end = strtotime($_GET['end']);
			$end = $end+(3600*24);
			$where .= " and dateline <".$end;
		}
		//价格
		if ($_GET['min']) {
			$where .= " and rent >".intval($_GET['min']);
		}
		if ($_GET['max']) {
			$where .= " and rent <".intval($_GET['max']);
		}
		//网号
		if($_GET['netid']){
			$where .= " and netid='{$_GET['netid']}'";
		}
		//地址
		if ($_GET['address'] && $_GET['address'] != '输入关键字(楼盘名或地段等)') {
			$where .= " and address like '%{$_GET['address']}%'";
		}
		return $where;
	}
	public function search(){
		$this->display();
	}
	/**
	 * excel 导入
	 *
	 * @param string $file
	 * @return array
	 */
	public function import(){
		if($_FILES){
			
			$type = intval($_POST['type']);
			$file=$this->_upFile();
			$excel = $this->_excelToArray($file,$type);

			$db = model();
			$apartment = $db->table('apartment')->select();//户型
			$certificate = $db->table('certificate')->select();//证书
			$decoration = $db->table('decoration')->select();//装修
			$structure = $db->table('structure')->select();// 结构			
			$time = time();
			foreach($excel as $key => $val){
				$val = $this->_htmlspecialchars($val);
				if ($type==1) {
					$insert['address']=$val[1];
					$insert['apartment']=$this->_property($val[2],$apartment,'apartment');
					$insert['shi']=$val[3];
					$insert['ting']=$val[4];
					$insert['wei']=$val[5];	
					$insert['chu']=$val[6];	
					$insert['yang']=$val[7];
					$insert['tu']=$val[8];
					$insert['floor']=$val[9];
					$insert['area']=$val[10];		
					$insert['decoration']=$this->_property($val[11],$decoration,'decoration');
					$insert['remark']=$val[12];
					$insert['rent']=$val[13];
					$insert['netid']=$val[14];
					$insert['rented']=0;
				}
				if ($type==2) {
					$insert['address']=$val[1];
					$insert['apartment']=$this->_property($val[2],$apartment,'apartment');
					$insert['shi']=$val[3];
					$insert['ting']=$val[4];
					$insert['wei']=$val[5];	
					$insert['chu']=$val[6];	
					$insert['yang']=$val[7];
					$insert['tu']=$val[8];
					$insert['floor']=$val[9];
					$insert['area']=$val[10];
					$insert['certificate']=$this->_property($val[11],$certificate,'certificate');
					$insert['structure']=$this->_property($val[12],$structure,'structure');//
					$insert['decoration']=$this->_property($val[13],$decoration,'decoration');
					$insert['remark']=$val[14];
					$insert['rent']=$val[15];
					$insert['netid']=$val[16];
					$insert['rented']=0;
				}
				$insert['uid']=$this->_G['member']['uid'];
				$insert['type']=$type;
				$insert['dateline'] = $time;
				$insert['year']=date('Y',$time);
				$insert['month']=date('n',$time);
				$insert['day']=date('j',$time);
				if (empty($insert['netid']) || empty($insert['address']) || empty($insert['apartment']) || empty($insert['rent'])) {				
					continue;					
				}
				$eid=$db->table('estate')->data($insert)->insert();
				
				//更新统计
				$data = array(
				'eid'=>$eid,
				'year'=>date('Y',$time),
				'month'=>date('n',$time),
				'day'=>date('j',$time),
				'username'=>$insert['netid'],
				'num'=>1
				);
				$db->table('count')->data($data)->insert();
				//更新统计end
			}
			//删除空数据
			$db->table('estate')->where("netid=''")->delete();
			$db->table('count')->where("username=''")->delete();
			$this->success('导入成功');
			exit;
		}

		//统计
		$time = time();
		$condition = array(
		'year'=>date('Y',$time),
		'month'=>date('n',$time),
		'day'=>date('j',$time),
		'username'=>$this->_G['member']['username'],
		);
		$db = model();

		$estate_count = $db->table('count')->where($condition)->count();
		$this->assign('today_count',$estate_count);
		$type = intval($_GET['type']) ? intval($_GET['type']) : 1;
		$all_count = $db->table('count')->where("username='{$this->_G['member']['username']}' ")->count();
		$this->assign('all_count',$all_count);
		$this->assign('type',$type);
		$this->display();
	}
	
	//自动添加属性
	private function _property($str,&$arr,$model){
		if (empty($str)) {
			return '';
		}
		
		//检测是否存在
		if (is_array($arr)) {
			foreach ($arr as $val){				
				if (strcasecmp($str,$val['name'])==0) {
					//var_dump($str);var_dump($val['name']);echo "<br>";
					return $val['id'];
				}
			}
		}
		//处理房屋类型,如果上面检测不存在则采用默认值
		if($model=='apartment'){
			return 1;
		}
		
		//var_dump($str);var_dump($val['name']);exit;
		//插入
		$db=model($model);
		$insert = array(
		'name'=>$str,
		'display'=>0,
		);
		$insert_id = $db->data($insert)->insert();
		//新插入数据保存到变量
		$arr[] = array(
		'id'=>$insert_id,
		'name'=>$str,
		'display'=>0,
		);
		return $insert_id;
	}
	//取得属性并用id作为key
	private function getProperty($model='apartment'){
		$db = model($model);
		$reslut = $db->order('sort desc,id asc')->select();
		if (!$reslut) return ;
		foreach ($reslut as $val){
			$return[$val['id']] = $val;
		}
		return $return;
	}
	/**
	 * excel 导出
	 *
	 * @param string $file
	 * @return array
	 */
	public function export($data,$type){
		if ($type==1) {
			$excel[] = array(
			array('val'=>'地址','align'=>'center','width'=>50),
			array('val'=>'楼层','align'=>'center','width'=>10),
			array('val'=>'房产类型','align'=>'center','width'=>20),	
			array('val'=>'户型','align'=>'center','width'=>20),				
			array('val'=>'面积','align'=>'center','width'=>10),
			array('val'=>'装修','align'=>'center','width'=>10),
			array('val'=>'备注','align'=>'center','width'=>50),
			array('val'=>'月租','align'=>'center','width'=>10),
			array('val'=>'网号','align'=>'center','width'=>10),
			array('val'=>'租否','align'=>'center','width'=>10),
			);
			foreach($data as $key=>$val){
				$excel[] = array(
				array('val'=>$val['address']),
				array('val'=>$val['floor']),
				array('val'=>$val['aname']),
				array('val'=>$val['huxing']),
				array('val'=>$val['area']),
				array('val'=>$val['dname']),
				array('val'=>$val['remark']),
				array('val'=>$val['rent']),
				array('val'=>$val['netid']),
				array('val'=>$val['rented'] ? '是':'否'),
				);
			}
			$title = "出租房源";
		}
		if ($type==2) {
			$excel[] = array(
			array('val'=>'地址','align'=>'center','width'=>50),
			array('val'=>'楼层','align'=>'center','width'=>10),
			array('val'=>'房产类型','align'=>'center','width'=>20),
			array('val'=>'户型','align'=>'center','width'=>20),
			array('val'=>'面积','align'=>'center','width'=>10),
			array('val'=>'权属','align'=>'center','width'=>10),
			array('val'=>'结构','align'=>'center','width'=>10),
			array('val'=>'装修','align'=>'center','width'=>10),
			array('val'=>'备注','align'=>'center','width'=>50),
			array('val'=>'售价','align'=>'center','width'=>10),
			array('val'=>'网号','align'=>'center','width'=>10),
			array('val'=>'售否','align'=>'center','width'=>10),
			);

			foreach($data as $key=>$val){
				$excel[] = array(
				array('val'=>$val['address']),
				array('val'=>$val['floor']),
				array('val'=>$val['aname']),
				array('val'=>$val['huxing']),
				array('val'=>$val['area']),
				array('val'=>$val['cname']),
				array('val'=>$val['sname']),
				array('val'=>$val['dname']),
				array('val'=>$val['remark']),
				array('val'=>$val['rent']),
				array('val'=>$val['netid']),
				array('val'=>$val['rented'] ? '是':'否'),
				);
			}
			$title = "出售房源";
		}
		$putout = new ExcelExport($title);
		foreach($excel as $val){
			$putout->setCells($val);
		}
		$putout->save();

	}
	/**
     * 房源审核
     *
     
	public function status(){
		$id = intval($_GET['id']);
		if ($id) {
			$status[]=$id;
		}else {
			$status = $_POST['id'];
		}
		$db = model('estate');
		foreach ($status as $val){
			$id = intval($val);
			$where['id']=$id;
			if ($this->_G['member']['usergroup'] != 1){
				$where['uid']=$this->_G['member']['uid'];
			}
			$where = "id=".$id;
			$update['status']=1;
			$db->where($where)->data($update)->update();
		}
		$this->success('审核成功');
	}*/



	/**
	 * 数据统计
	 *
	 */
	public function statistics(){
		$db = model('count');
		//$db->where("username=''")->delete();//清除空数据
		$time = time();
		$year=empty($_GET['year']) ? date('Y',$time) : $_GET['year'];
		$month=empty($_GET['month']) ? date('n',$time) : $_GET['month'];
		$day=date('j',$time);
		$day_count = date('t',strtotime("{$year}-{$month}-01"));
		$where = "`year`=$year";
		$where .= " and month=$month";

		if($_GET['username'] && $_GET['username']!='请输入网号'){
			$where .= " and username like '%{$_GET['username']}%'";
		}



		/*$result = $db->where($where)->order("username asc")->select();
		$list = array();
		if ($result)
		foreach ($result as $val){
		$list[$val['username']][$val['day']] = $val['num'];
		$list[$val['username']]['netid'] = $val['username'];
		}*/
		$sql = "select `username`,`year`,`month`,`day`, count(id) as num from {pre}count where $where group by year,month,day,username order by username ASC";
		$result = $db->query($sql);

		$list = array();
		if ($result)
		foreach ($result as $val){
			$list[$val['username']][$val['day']] = $val['num'];
			$list[$val['username']]['netid'] = $val['username'];
		}
		$this->assign('day_count',$day_count);
		$this->assign('list',$list);
		$this->display();
	}
	//图片上传
	private function _upFile(){

		/*上传文件处理*/
		$upload = new UploadFile();// 实例化上传类

		$upload->maxSize  = 3145728 ;// 设置附件上传大小
		$upload->allowExts  = array('xls', 'xlsx');// 设置附件上传类型

		//$upload->saveRule = time().'-'.random(4,true); //生成文件名称
		$upload->savePath =  'upfile/';// 设置附件上传目录

		if(!$upload->upload()) {// 上传错误提示错误信息
			$error = $upload->getErrorMsg();
			$this->error($error);
			return false;
		}else{// 上传成功
			$excel=$upload->getUploadFileInfo();
			$insert = array(
			'filename'=>$excel['excel']['name'],
			'savepath'=>$excel['excel']['savepath'],
			'savename'=>$excel['excel']['savename'],
			'size'=>$excel['excel']['size'],
			'uid'=>$this->_G['member']['uid'],
			'dateline'=>time()
			);
			$db = model('file');
			$db->data($insert)->insert();
			return $excel['excel']['savepath'].$excel['excel']['savename'];

		}
		/*上传文件处理结束*/
	}
	public function add(){

		if ($_POST) {
			//房源导入时间限制
			if ($this->_G['member']['usergroup'] != 1) {
				$this->timelimit();
			}
			$this->do_add();
			exit;
		}
		$type = intval($_GET['type']) ? intval($_GET['type']) : 1;

		$array=array(
		'type'=> $type,
		'apartment' => model('apartment')->where("display=1")->order("sort DESC")->select(),
		'certificate' => model('certificate')->where("display=1")->order("sort DESC")->select(),
		'decoration' => model('decoration')->where("display=1")->order("sort DESC")->select(),
		'structure' => model('structure')->where("display=1")->order("sort DESC")->select(),
		);
		$this->assign($array);
		$this->display();
	}
	public function do_add(){
		$db = model('estate');
		$rule = array(
		array('address','require','请填写地址'),
		array('floor','require','请填写楼层'),
		array('area','require','请填写面积'),
		);
		$insert = $db->validate($rule)->checkData();
		$error = $db->getError();
		if ($error) {
			$this->error($error);
		}
		$insert['uid']=$this->_G['member']['uid'];
		$insert['dateline'] = time();
		if ($this->_G['member']['usergroup'] != 1) {
			$insert['netid']=$this->_G['member']['username'];
		}
		

		if(!$insert['netid']) {
			$this->error('请填写网号');
		}
		$eid = $db->data($insert)->insert();

		//更新统计
		$time = time();
		$data = array(
		'eid'=>$eid,
		'year'=>date('Y',$time),
		'month'=>date('n',$time),
		'day'=>date('j',$time),
		'username'=>$insert['netid'],
		'num'=>1
		);
		$db->table('count')->data($data)->insert();

		$this->success('添加成功');
	}
	public function edit(){
		if ($_POST) {
			$this->do_edit();
			exit;
		}
		$where['id'] = intval($_GET['id']);
		if ($this->_G['member']['usergroup'] != 1) {
			$where['uid']=$this->_G['member']['uid'];
		}
		$db = model('estate');
		$estate = $db->where($where)->find();
		if(!$estate){
			$this->error('你的记录里找不到该条数据');
		}
		$array=array(
		'type'=>intval($_GET['type']),
		'estate'=> $estate,
		'apartment' => model('apartment')->where("display=1")->order("sort DESC")->select(),
		'certificate' => model('certificate')->where("display=1")->order("sort DESC")->select(),
		'decoration' => model('decoration')->where("display=1")->order("sort DESC")->select(),
		'structure' => model('structure')->where("display=1")->order("sort DESC")->select(),
		);
		$this->assign($array);
		$this->display();
	}
	public function do_edit(){
		$where['id'] = intval($_POST['id']);
		if ($this->_G['member']['usergroup'] != 1) {
			$where['uid']=$this->_G['member']['uid'];
			$where['status']=0;
		}
		$db = model('estate');
		$rule = array(
		array('address','require','请填写地址'),
		array('floor','require','请填写楼层'),
		array('area','require','请填写面积'),
		);
		$update = $db->validate($rule)->checkData();
		$error = $db->getError();
		if ($error) {
			$this->error($error);
		}

		$db->where($where)->data($update)->update();
		$this->success('修改成功');

	}
	/**
	 * 删除
	 *
	 */
	public function del(){
		$del[]=intval($_GET['id']);
		if ($_POST) {
			$del=$_POST['id'];
		}
		$db = model('estate');
		$count = model('count');
		foreach ($del as $val){
			$where['id'] = intval($val);
			if ($this->_G['member']['usergroup'] != 1) {
				$where['uid']=$this->_G['member']['uid'];
				$where['status']=0;
			}
			$db->where($where)->delete();
			$count->where("eid=".$where['id'])->delete();//删除统计信息
		}
		$this->success('删除成功');
	}
	public function refresh(){
		$id = intval($_GET['id']);
		if ($id) {
			$refresh[]=$id;
		}else {
			$refresh = $_POST['id'];
		}
		$db = model('estate');
		$count = model('count');

		$where = array();
		foreach ($refresh as $val){
			$where['id'] = intval($val);
			if ($this->_G['member']['usergroup'] != 1) {
				$where['netid']=$this->_G['member']['username'];
			}
			//$update['dateline']=time();
			//$status = $db->where($where)->data($update)->update();
			//$db->where($where)->data("refresh = refresh+1")->update();//更新刷新次数
			//更新统计 复制数据
			$estate = $db->where($where)->find();
			$new = $estate;
			$new['dateline']=time();
			$new['status']=0;
			unset($new['id']);
			$eid = $db->data($new)->insert();
			if($estate){
				$time = time();
				$count_data = array(
				'eid'=>$eid,
				'year'=>date('Y',$time),
				'month'=>date('n',$time),
				'day'=>date('j',$time),
				'username'=>$estate['netid'],
				'num'=>1
				);
				$count->data($count_data)->insert();//更新成功增添记录条数
			}

		}

		$this->success('重新发布成功');
	}
	public function rented(){
		$update['rented'] = intval($_GET['rented']);

		if ($_POST['id']) {
			$db = model('estate');
			foreach ($_POST['id'] as $id){
				$where['id']=intval($id);
				$db->where($where)->data($update)->update();

			}
		}
		$this->success('更新成功');
	}
	public function top(){
		$where['id'] = intval($_GET['id']);
		$update['top']=1;
		$db = model('estate');			
		$db->where($where)->data($update)->update();

		$this->success('置顶成功');
	}
	public function notop(){
		$where['id'] = intval($_GET['id']);
		$update['top']=0;
		$db = model('estate');			
		$db->where($where)->data($update)->update();

		$this->success('取消置顶成功');
	}
	/**
	 * excel读取返回数组
	 *
	 * @param string $file
	 * @return array
	 */
	private function _excelToArray($file,$type){
		require_once CP_PATH.'ext/PHPExcel/IOFactory.php';
		$extend = pathinfo($file);
		$extend = strtolower($extend["extension"]);
		$reader_type = array(
		'xls'=> "Excel5",
		'xlsx'=>"Excel2007",
		);
		/*require_once 'Lib/ORG/Classes/PHPExcel/IOFactory.php';
		$reader = PHPExcel_IOFactory::createReader('Excel2007'); //设置以Excel5格式(Excel97-2003工作簿)
		$PHPExcel = $reader->load("1.xlsx"); // 载入excel文件*/
		$PHPExcel = PHPExcel_IOFactory::load($file);
		$sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
		$highestRow = $sheet->getHighestRow(); // 取得总行数
		$highestColumm = $sheet->getHighestColumn(); // 取得总列数
		//$highestColumm = 'Q';
		//判断类型
		$k2 = $sheet->getCell('O2')->getValue();

		if ($type==1 && $k2!='网号') {
			$this->error('导入数据错误');
		}
		$i2 = $sheet->getCell('Q2')->getValue();

		if ($type==2 && $i2!='网号') {			
			$this->error('导入数据错误');
		}
		/** 循环读取每个单元格的数据 */
		for ($row = 3; $row <= $highestRow; $row++){//行数是以第2行开始
			for ($column = 'A'; $column <= $highestColumm; $column++) {//列数是以A列开始
				$dataset[$row][] = $sheet->getCell($column.$row)->getValue();
				//echo $column.$row.":".$sheet->getCell($column.$row)->getValue()."<br />";
			}
		}
		return $dataset;
	}
	//添加导入房源时间限制
	public function timelimit(){
		$db = model('site');
		$site = $db->where("id=1")->find();
		
		$time = time();
		if($site['close']&&$time>$site['closetime']){
			$this->error($site['closetext']);
		}
		$hour = date('G',$time);//小时
		$minute= date('i',$time);//分
		$week = date('w',$time);//星期几
		if ($week==0) {//星期天
			if ($hour<8 or $hour>14) {
				$this->error('对不起现在不可以导入房源');
			}
		}else{//周一至周六
			if($hour<8 or $hour>20) $this->error('对不起现在不可以导入房源');
			if ($hour==20 && $minute>=30) {
				$this->error('对不起现在不可以导入房源');
			}
		}
	}
	/**
	 * 自动审核
	 *
	 */
	private function auto_status(){
		$time = time();
		$hour = date('G',$time);//小时
		$minute= date('i',$time);//分
		$week = date('w',$time);//星期几
		$timestr = date('Y-m-d',$time);

		$timestr = strtotime($timestr);//今天凌晨的时间戳
		$where = "dateline < $timestr";//昨天的数据
		$update['status']=1;
		$db = model('estate');
		//当天数据自动审核
		if ($week==0) {//星期天
			if ($hour >13) {
				$db->data($update)->update();
			}
		}else{//周一至周六
			if($hour >19) {
				$db->data($update)->update();
			}
		}
		//其他时间 昨天数据自动审核
		$db->data($update)->where($where)->update();
	}
	private function _huxing($data){
		$str = "";
		$data['shi'] && $str .= $data['shi']."室";
		$data['ting'] && $str .= $data['ting']."厅";
		$data['wei'] && $str .= $data['wei']."卫";
		$data['chu'] && $str .= $data['chu']."厨";
		$data['yang'] && $str .= $data['yang']."阳";
		if($data['tu']=='是') $str .= "凸";
		return $str;
	}

}